import 'package:flutter/material.dart';
import 'package:flutter/animation.dart';
import 'package:flutter_demo/utils/smaple.dart';


class AnimationTest extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _AnimationTestState();
  }
}

class _AnimationTestState extends State<AnimationTest>
    with SingleTickerProviderStateMixin {
  Animation<double> _animation;
  AnimationController _animationController;

  @override
  void initState() {
    super.initState();

    _animationController = AnimationController(
        duration: Duration(milliseconds: 1500), vsync: this);
    _animation = Tween(begin: 0.0, end: 400.0).animate(_animationController)
      ..addListener(() {
        setState(() {});
      });

    _animationController.addStatusListener((status) {
      print("$status");

      if (status == AnimationStatus.completed) {
        _animationController.reverse();
      } else if( status == AnimationStatus.dismissed){
        _animationController.forward();
      }
    });

    _animationController.forward();
  }

  @override
  void dispose() {
    super.dispose();
    _animationController.dispose();
  }

  @override
  Widget build(BuildContext context) {
//    return Center(
//      child: Container(
//        width: _animation.value,
//        height: _animation.value,
//        color: Color(0xffcc9933),
//        child: Center(
//          child: Text(
//            "float button view",
//            style: TextStyle(color: Color(0xffffffff)),
//          ),
//        ),
//      ),
//    );
    return Align(
        alignment: Alignment.bottomCenter,
        child: Container(
          margin: EdgeInsets.only(bottom: _animation.value),
          width: 100,
          height: 100,
          color: Color(0xffcc9933),
          child: Center(
            child: Text(
              "float button view",
              style: TextStyle(color: Color(0xffffffff)),
            ),
          ),
        ));
  }
}
